package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcPosts;
import com.ruoyi.system.service.IIcPostsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子Controller
 * 
 * @author ruoyi
 * @date 2024-07-11
 */
@Controller
@RequestMapping("/system/icPosts")
public class IcPostsController extends BaseController
{
    private String prefix = "system/icPosts";

    @Autowired
    private IIcPostsService icPostsService;

    @RequiresPermissions("system:icPosts:view")
    @GetMapping()
    public String icPosts()
    {
        return prefix + "/icPosts";
    }

    /**
     * 查询帖子列表
     */
    @RequiresPermissions("system:icPosts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcPosts icPosts)
    {
        startPage();
        List<IcPosts> list = icPostsService.selectIcPostsList(icPosts);
        return getDataTable(list);
    }

    /**
     * 导出帖子列表
     */
    @RequiresPermissions("system:icPosts:export")
    @Log(title = "帖子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcPosts icPosts)
    {
        List<IcPosts> list = icPostsService.selectIcPostsList(icPosts);
        ExcelUtil<IcPosts> util = new ExcelUtil<IcPosts>(IcPosts.class);
        return util.exportExcel(list, "帖子数据");
    }

    /**
     * 新增帖子
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存帖子
     */
    @RequiresPermissions("system:icPosts:add")
    @Log(title = "帖子", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcPosts icPosts)
    {
        return toAjax(icPostsService.insertIcPosts(icPosts));
    }

    /**
     * 修改帖子
     */
    @RequiresPermissions("system:icPosts:edit")
    @GetMapping("/edit/{postId}")
    public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
    {
        IcPosts icPosts = icPostsService.selectIcPostsByPostId(postId);
        mmap.put("icPosts", icPosts);
        return prefix + "/edit";
    }

    /**
     * 修改保存帖子
     */
    @RequiresPermissions("system:icPosts:edit")
    @Log(title = "帖子", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcPosts icPosts)
    {
        return toAjax(icPostsService.updateIcPosts(icPosts));
    }

    /**
     * 删除帖子
     */
    @RequiresPermissions("system:icPosts:remove")
    @Log(title = "帖子", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icPostsService.deleteIcPostsByPostIds(ids));
    }
}
